package com.yuju.group.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yuju.common.core.dao.IBaseDao;
import com.yuju.common.core.service.AbstractBaseService;
import com.yuju.group.dao.IProtocolCustomDao;
import com.yuju.group.dao.entity.ProtocolCustom;
import com.yuju.group.model.ProtocolCustomModel;
import com.yuju.group.service.IProtocolCustomService;
import com.yuju.util.Utils;

/**
 * 类名：ProtocolCustomServiceImpl  <br />
 *
 * 功能：
 *
 * @author : jiaokn <br />
 * @Date : 2017年11月24日 上午10:50:53  <br />
 * @version : 1.1 <br />
 */
@Service
public class ProtocolCustomServiceImpl extends AbstractBaseService<ProtocolCustomModel, ProtocolCustom, String> implements IProtocolCustomService {
	
	@Autowired
	private IProtocolCustomDao protocolCustomDao;
	
	@Override
	public IBaseDao<ProtocolCustomModel, ProtocolCustom, String> getDao() {
		// TODO Auto-generated method stub
		return protocolCustomDao;
	}
	
	
	/**
	 * 功能: 新增协议单位<br/>
	 * 
	 * 重写：jiaokn <br/>
	 * 
	 * @Date ：2017年11月22日 下午4:12:30<br/>
	 * 
	 * @param protocolCustomModel
	 * @return <br/>
	 * @see com.yuju.common.core.service.AbstractBaseService#save(java.lang.Object)
	 */
	@Override
	public int save(ProtocolCustomModel protocolCustomModel){
		protocolCustomModel.setId(Utils.getUUID());
		protocolCustomModel.setGmtCreate(new Date());
		protocolCustomModel.setGmtModified(new Date());
		return super.save(protocolCustomModel);
	}


	/**
	 * 功能:验证名称是否重复 <br/>
	 * 
	 * 重写：jiaokn <br/>
	 * 
	 * @Date ：2017年12月8日 下午3:03:29<br/>
	 * 
	 * @param protocolCustomModel
	 * @return <br/>
	 * @see com.yuju.group.service.IProtocolCustomService#validateName(com.yuju.group.model.ProtocolCustomModel)
	 */
	@Override
	public boolean validateName(ProtocolCustomModel protocolCustomModel) {
		boolean flag = false;
		if(protocolCustomModel.getId()==null){
			List<ProtocolCustomModel> list = this.list(protocolCustomModel);
			if(list==null || list.size()==0){
				flag = true;
			}
		}else{
			ProtocolCustomModel model = this.findById(protocolCustomModel.getId());
			if(model.getName().equals(protocolCustomModel.getName())){
				flag = true;
			}else{
				protocolCustomModel.setId(null);
				List<ProtocolCustomModel> list = this.list(protocolCustomModel);
				if(list==null || list.size()==0){
					flag = true;
				}
			}
		}
		return flag;
	}

	
	
	

}
